package com.shinetech.client.screen;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class SystemMenuBar
{
    private MenuBar menuBar;


    public SystemMenuBar()
    {
        menuBar = create();
    }
    
    public MenuBar getMenuBar() { return menuBar;}

    private MenuBar create()
    {
        // Create a command that will execute on menu item selection
        Command menuCommand = new Command()
        {
            public void execute()
            {
                // Create the dialog box
                final DialogBox dialogBox = new DialogBox();
                dialogBox.setTitle("About");
                dialogBox.setText("Built with GWT Version :" + GWT.getVersion());
                dialogBox.setAnimationEnabled(true);
                Button closeButton = new Button("close");
                VerticalPanel dialogVPanel = new VerticalPanel();
                dialogVPanel.setWidth("100%");
                dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
                dialogVPanel.add(closeButton);
                dialogBox.setWidget(dialogVPanel);
                closeButton.addClickListener(new ClickListener()
                {
                    public void onClick(Widget sender)
                    {
                        dialogBox.hide();
                    }
                });
                dialogBox.show();
            }
        };

        // Create a menu bar
        MenuBar menu = new MenuBar();
        menu.setAutoOpen(true);
        menu.setWidth("100%");
        menu.setAnimationEnabled(true);

        // Create System Menu
        MenuBar systemMenu = new MenuBar(true);
        menu.addItem(new MenuItem("System", systemMenu));
        systemMenu.addItem("Login", menuCommand);
        systemMenu.addItem("Logout", menuCommand);

        // Create the help menu
        MenuBar helpMenu = new MenuBar(true);
        menu.addSeparator();
        menu.addItem(new MenuItem("Help", helpMenu));
        helpMenu.addItem("About", menuCommand);

        // Return the menu
        menu.ensureDebugId("cwMenuBar");
        return menu;
    }

}
